package com.atguigu.dao;

import com.atguigu.bean.Entity;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@Repository
public class EntityDao {
    private static Map<Integer, Entity> Entitys = null;
    static{
        Entitys = new HashMap<Integer, Entity>();
        Entitys.put(1001, new Entity(1001, "E-AA", "aa@163.com", 1));
        Entitys.put(1002, new Entity(1002, "E-BB", "bb@163.com", 1));
        Entitys.put(1003, new Entity(1003, "E-CC", "cc@163.com", 0));
        Entitys.put(1004, new Entity(1004, "E-DD", "dd@163.com", 0));
        Entitys.put(1005, new Entity(1005, "E-EE", "ee@163.com", 1));
    }
    private static Integer initId = 1006;
    public void save(Entity Entity){
        if(Entity.getId() == null){
            Entity.setId(initId++);
        }
        Entitys.put(Entity.getId(), Entity);
    }
    public Collection<Entity> getAll(){
        return Entitys.values();
    }
    public Entity get(Integer id){
        return Entitys.get(id);
    }
    public void delete(Integer id){
        Entitys.remove(id);
    }

}
